package cn.usts.deu.controller;

import cn.usts.deu.pojo.User1;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class FastJsonController {
    @RequestMapping("/fast1")
    public void fastJson1(){
        User1 user2 = new User1("tom2",13,"男");
        User1 user3 = new User1("tom3",11,"女");
        User1 user4 = new User1("tom4",14,"女");
        User1 user5 = new User1("tom5",12,"男");
        User1 user6 = new User1("tom6",11,"男");
        List<User1> list= new ArrayList<User1>();
        list.add(user2);
        list.add(user3);
        list.add(user4);
        list.add(user5);
        list.add(user6);
        // Java对象 转 JSON字符串
        String lis1 = JSON.toJSONString(list);
        System.out.println(lis1);
        String user = JSON.toJSONString(user2);
        System.out.println(user);

        //json 字符串转java对象
        User1 javaProject_user = JSON.parseObject(user,User1.class);

    }
}
